package com.mes.cloud.controller;

import com.mes.cloud.dto.BmeBcDesignDTO;
import com.mes.cloud.service.BmeBcDesignService;
import com.mes.cloud.utils.JSONResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * h5活动设计
 *
 * @author wxm
 * @Time 2020-5-12
 */
@RestController
@RequestMapping("/bmeBcDesign")
public class BmeBcDesignController {
    private static final Logger LOGGER = LoggerFactory.getLogger(BmeBcDesignController.class);

    @Autowired
    private BmeBcDesignService bmeBcDesignService;

    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    public JSONResult getList(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success(bmeBcDesignService.getList(map));
        return result;
    }

    @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
    public JSONResult getPageList(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success(bmeBcDesignService.getPageList(map));
        return result;
    }

    @RequestMapping(value = "/getCount", method = RequestMethod.POST)
    public JSONResult getCount(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success(bmeBcDesignService.getCount(map));
        return result;
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONResult insert(@RequestBody BmeBcDesignDTO bmeBcDesignDTO) {
        bmeBcDesignService.insert(bmeBcDesignDTO);
        JSONResult result = JSONResult.success();
        return result;
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JSONResult update(@RequestBody BmeBcDesignDTO bmeBcDesignDTO) {
        bmeBcDesignService.update(bmeBcDesignDTO);
        JSONResult result = JSONResult.success();
        return result;
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JSONResult delete(@RequestBody BmeBcDesignDTO bmeBcDesignDTO) {
        bmeBcDesignService.delete(bmeBcDesignDTO.getId());
        JSONResult result = JSONResult.success();
        return result;
    }

    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public JSONResult get(@RequestBody BmeBcDesignDTO bmeBcDesignDTO) {
        BmeBcDesignDTO BmeBcDesignDTOReturn = bmeBcDesignService.get(bmeBcDesignDTO.getId());
        JSONResult result = JSONResult.success(BmeBcDesignDTOReturn);
        return result;
    }

    @RequestMapping(value = "/getByCode", method = RequestMethod.POST)
    public JSONResult getByCode(@RequestBody BmeBcDesignDTO bmeBcDesignDTO) {
        JSONResult jsonResult = null;
        try {
            BmeBcDesignDTO bmeBcDesignDTOReturn = bmeBcDesignService.getByCode(bmeBcDesignDTO.getCode());
            jsonResult = JSONResult.success(bmeBcDesignDTOReturn);
        } catch (Exception e) {
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        return jsonResult;
    }

    /**
     * @param map
     * @Description 批量删除
     * @date: 2019/6/27 14:44
     * @return: com.mes.cloud.util.JSONResult
     */
    @RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
    public JSONResult batchDelete(@RequestBody Map<Object, Object> map) {
        JSONResult jsonResult = null;
        try {
            bmeBcDesignService.batchDelete(map);
            jsonResult = JSONResult.success();
        } catch (Exception e) {
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        return jsonResult;
    }

    /**
     * @param map
     * @Description 禁用启用
     * @date: 2019/6/27 14:44
     * @return: com.mes.cloud.util.JSONResult
     */
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public JSONResult enable(@RequestBody Map<Object, Object> map) {
        JSONResult jsonResult = null;
        try {
            long count = bmeBcDesignService.enable(map);
            jsonResult = JSONResult.success();
        } catch (Exception e) {
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        return jsonResult;
    }
}
